<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>为 PHP 的值生成 XML</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.xmlrpc-decode.html">« xmlrpc_decode</a></li>
      <li style="float: right;"><a href="function.xmlrpc-encode.html">xmlrpc_encode »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.xmlrpc.html">XML-RPC 函数</a></li>
    <li>为 PHP 的值生成 XML</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.xmlrpc-encode-request" class="refentry">
   <div class="refnamediv">
    <h1 class="refname">xmlrpc_encode_request</h1>
    <p class="verinfo">(PHP 4 &gt;= 4.1.0, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">xmlrpc_encode_request</span> &mdash; <span class="dc-title">为 PHP 的值生成 XML</span></p>

   </div>
 <div class="refsect1 description" id="refsect1-function.xmlrpc-encode-request-description">
  <h3 class="title">说明</h3>
     <div class="methodsynopsis dc-description">
      <span class="methodname"><strong>xmlrpc_encode_request</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$method</code></span>, <span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">$params</code></span>, <span class="methodparam"><span class="type">array</span> <code class="parameter">$output_options</code><span class="initializer"> = ?</span></span>): <span class="type">string</span></div>

     <div class="warning"><strong class="warning">警告</strong><p class="simpara">此函数是<em class="emphasis">实验性</em>的。此函数的表象，包括名称及其相关文档都可能在未来的
PHP 发布版本中未通知就被修改。使用本函数风险自担。</p></div>
   </div>


 <div class="refsect1 parameters" id="refsect1-function.xmlrpc-encode-request-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">method</code></dt>

     <dd>

      <p class="para">
       Name of the method to call.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">params</code></dt>

     <dd>

      <p class="para">
       Method parameters compatible with method signature.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">output_options</code></dt>

     <dd>

      <p class="para">
       Array specifying output options may contain (default values are
       emphasised):
       <ul class="itemizedlist">
        <li class="listitem"><p class="para">output_type: php, <em class="emphasis">xml</em></p></li>
        <li class="listitem"><p class="para">verbosity: no_white_space, newlines_only, <em class="emphasis">pretty</em></p></li>
        <li class="listitem"><p class="para">escaping: cdata, <em class="emphasis">non-ascii, non-print, markup</em>
          (may be a string with one value or an array with multiple values)</p></li>
        <li class="listitem"><p class="para">version: simple, <em class="emphasis">xmlrpc</em>, soap 1.1, auto</p></li>
        <li class="listitem"><p class="para">encoding: <em class="emphasis">iso-8859-1</em>, other character set supported by iconv</p></li>
       </ul>
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 
 <div class="refsect1 returnvalues" id="refsect1-function.xmlrpc-encode-request-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns a string containing the XML representation of the request.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.xmlrpc-encode-request-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-5365">
    <p><strong>示例 #1 XMLRPC client functions example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$request&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">xmlrpc_encode_request</span><span style="color: #007700">(</span><span style="color: #DD0000">"method"</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">3</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">$context&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">stream_context_create</span><span style="color: #007700">(array(</span><span style="color: #DD0000">'http'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'method'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"POST"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'header'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"Content-Type:&nbsp;text/xml"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'content'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">$request<br /></span><span style="color: #007700">)));<br /></span><span style="color: #0000BB">$file&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">file_get_contents</span><span style="color: #007700">(</span><span style="color: #DD0000">"http://www.example.com/xmlrpc"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$context</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$response&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">xmlrpc_decode</span><span style="color: #007700">(</span><span style="color: #0000BB">$file</span><span style="color: #007700">);<br />if&nbsp;(</span><span style="color: #0000BB">$response&nbsp;</span><span style="color: #007700">&amp;&amp;&nbsp;</span><span style="color: #0000BB">xmlrpc_is_fault</span><span style="color: #007700">(</span><span style="color: #0000BB">$response</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">trigger_error</span><span style="color: #007700">(</span><span style="color: #DD0000">"xmlrpc:&nbsp;</span><span style="color: #0000BB">$response</span><span style="color: #007700">[</span><span style="color: #0000BB">faultString</span><span style="color: #007700">]</span><span style="color: #DD0000">&nbsp;(</span><span style="color: #0000BB">$response</span><span style="color: #007700">[</span><span style="color: #0000BB">faultCode</span><span style="color: #007700">]</span><span style="color: #DD0000">)"</span><span style="color: #007700">);<br />}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$response</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.xmlrpc-encode-request-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.stream-context-create.html" class="function" rel="rdfs-seeAlso">stream_context_create()</a> - 创建资源流上下文</span></li>
    <li class="member"><span class="function"><a href="function.file-get-contents.html" class="function" rel="rdfs-seeAlso">file_get_contents()</a> - 将整个文件读入一个字符串</span></li>
    <li class="member"><span class="function"><a href="function.xmlrpc-decode.html" class="function" rel="rdfs-seeAlso">xmlrpc_decode()</a> - 将 XML 译码为 PHP 本身的类型</span></li>
   </ul>
  </p>
 </div>

  </div></div></div></body></html>